package com.zoe.onelink.core.autoconfigure;

import com.alibaba.fastjson.parser.ParserConfig;
import com.zoe.onelink.core.property.FastJsonParserProperties;
import com.zoe.onelink.util.StrUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2021</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2021-11-17
 */
@Configuration(proxyBeanMethods = false)
@RequiredArgsConstructor
public class FastJsonAutoConfiguration implements InitializingBean {

    private final FastJsonParserProperties fastJsonParserProperties;

    @Override
    public void afterPropertiesSet() throws Exception {
        ParserConfig globalInstance = ParserConfig.getGlobalInstance();
        globalInstance.setAutoTypeSupport(this.fastJsonParserProperties.isAutoTypeSupport());
        globalInstance.setSafeMode(this.fastJsonParserProperties.isSafeMode());
        if (StrUtil.isNotBlank(this.fastJsonParserProperties.getAutoTypeAccept())) {
            globalInstance.addAccept(this.fastJsonParserProperties.getAutoTypeAccept());
        }
    }
}
